package com.pengcheng.taskapplication.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.pengcheng.taskapplication.R;
import com.pengcheng.taskapplication.model.Dict;

import java.util.List;

public class OccupationItemAdapter extends BaseAdapter {

	Context context;
	LayoutInflater inflater;
	List<Dict> dicts;
	int last_item;
	private int selectedPosition = -1;
	public OccupationItemAdapter(Context context, List<Dict> dicts){
		this.context = context;
		this.dicts = dicts;
		inflater= LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return dicts.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return dicts.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder  holder = null;
		if(convertView==null){
			convertView = inflater.inflate(R.layout.occupation_item_layout, null);
			holder = new ViewHolder();
			holder.tv_item=(TextView) convertView.findViewById(R.id.tv_item);
			convertView.setTag(holder);
		}
		else{
			holder=(ViewHolder)convertView.getTag();
		}

		Dict dict= dicts.get(position);
		holder.tv_item.setText(dict.getName());
		return convertView;
	}

	public static class ViewHolder{
		public TextView tv_item;

	}

	public void setSelectedPosition(int position) {
		selectedPosition = position;
	}

	public void setList(List<Dict> dicts) {
		this.dicts = dicts;
		notifyDataSetChanged();
	}

}
